# Maintainer: Jiuyang Liu <liujiuyang1994@gmail.com>
# Contributor: Emil Renner Berthing <aur@esmil.dk>

pkgname=riscv-openocd-git
_pkgname=${pkgname%-git}
pkgver=v20180629.r1749.gf4950b7c5
pkgrel=1
pkgdesc='Fork of OpenOCD that has RISC-V support'
arch=('x86_64' 'aarch64')
url='https://github.com/riscv/riscv-openocd'
license=('GPL')
depends=('libftdi' 'hidapi')
makedepends=('git')
source=("$pkgname::git+https://hub.fastgit.org/riscv/riscv-openocd#branch=riscv"
	"add-jimtcl-aarch64-compile-support.patch")
sha1sums=('SKIP'
          'c5077077a805f8c2fdaac4de8b9d7756aa8eb6b6')

pkgver() {
  cd "$srcdir/$pkgname"
  git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "$srcdir/$pkgname"
  git submodule update --init --recursive
  patch --forward --strip=1 --input="${srcdir}/add-jimtcl-aarch64-compile-support.patch"
}

build() {
  cd "$srcdir/$pkgname"

  ./bootstrap
  ./configure \
    --prefix=/usr \
    --program-prefix=riscv- \
    --disable-werror \
    --with-gnu-ld

  make pkgdatadir="/usr/share/$_pkgname"
}

package() {
  cd "$srcdir/$pkgname"
  make pkgdatadir="/usr/share/$_pkgname" DESTDIR="$pkgdir" install
  rm -r "$pkgdir/usr/share/info"
}

